deadd1f0ae26bf25aaafaaa90efc626a48013605,src/freenet/node/fcp/ClientGet.java,ClientGet,onSuccess,#FetchResult#ClientGetter#,153

Before Change


			try {
				fos = new FileOutputStream(tempFile);
			} catch (FileNotFoundException e) {
				ProtocolErrorMessage pm = new ProtocolErrorMessage(ProtocolErrorMessage.COULD_NOT_WRITE_FILE, false, null, identifier);
				trySendDataFoundOrGetFailed(pm);
				data.free();
				finish();
				return;

After Change


			try {
				fos = new FileOutputStream(tempFile);
			} catch (FileNotFoundException e) {
				postFetchProtocolErrorMessage = new ProtocolErrorMessage(ProtocolErrorMessage.COULD_NOT_WRITE_FILE, false, null, identifier);
				trySendDataFoundOrGetFailed();
				data.free();
				finish();
				return;
			}
			try {
				BucketTools.copyTo(data, fos, data.size());
			} catch (IOException e) {
				postFetchProtocolErrorMessage = new ProtocolErrorMessage(ProtocolErrorMessage.COULD_NOT_WRITE_FILE, false, null, identifier);
				trySendDataFoundOrGetFailed();
				data.free();
				try {
					fos.close();
				} catch (IOException e1) {
					// Ignore
				}
				finish();
				return;
			}
			try {
				fos.close();
			} catch (IOException e) {
				Logger.error(this, "Caught "+e+" closing file "+tempFile, e);
			}
			if(!tempFile.renameTo(targetFile)) {
				postFetchProtocolErrorMessage = new ProtocolErrorMessage(ProtocolErrorMessage.COULD_NOT_RENAME_FILE, false, null, identifier);
				trySendDataFoundOrGetFailed();
				// Don't delete temp file, user might want it.
			}
			data.free();